package java037004.HomeWork;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class HomeWork {
    public static void main(String[] args) {

    }
//    2登录程序
    public static void login(ArrayList<String> list){
        boolean flag = true;
        System.out.println("请输入用户名");
        String username = new Scanner(System.in).nextLine();
        if(list.contains(username)){
            int i = 3;
            while (flag) {
                System.out.println("请输入密码:");
                String password = new Scanner(System.in).nextLine();
                if (password.equals("123456")) {
                    System.out.println("登录成功!");
                    flag = false;
                }else {
                    i--;
                    if (i == 0) {
                        System.out.println("今日输入已到达上限!");
                        flag = false;
                    } else {
                        System.out.println("密码错误!还剩" + i + "次机会");
                    }

                }
            }
        }else{
            System.out.println("用户名错误!");
        }
    }
//    3号码加密
    public static void Encrypt(String str){
        String tmp = str.substring(3,7);
        str = str.replace(tmp,"****");
        System.out.println(str);
    }
//    5判断回文
    public static void HuiWen(String str){
        boolean flag = true;
        char[] charArray = str.toCharArray();
        for(int i = 0; i < str.length()/2; i++){
            String min = str.substring(i,i+1);
            String max = str.substring(str.length() - i - 1, str.length() - i);
            if(min.equals(max)){

            }else{
                flag = false;
                break;
            }
        }
        if(flag){
            System.out.println(str+":是回文");
        }else{
            System.out.println(str+":不是回文");
        }
    }
//    6各式命名
    public static void Form(String[] strArr){
        for(int i = 0; i < strArr.length; i++){
            String str = strArr[i];
            String newStr = "";
            if(str.endsWith("jpg") || str.endsWith("png") || str.endsWith("gif")){
                String[] tempArr = str.split("\\.");
                ArrayList<String> tempList = new ArrayList<String>();
                for(int j = 0; j < 6; j++){
                    if(j < 2){
                        tempList.add(""+new Random().nextInt(10));
                    }else{
                        tempList.add(""+(char)(new Random().nextInt(26)+97));
                    }
                }
                for(int j = 0; tempList.size() > 0; j++){
                    int num = new Random().nextInt(tempList.size());
                    newStr += tempList.get(num);
                    tempList.remove(num);
                }
                newStr += "."+tempArr[1];
                strArr[i] = newStr;
            }
        }
        for(String str:strArr){
            System.out.println(str);
        }
    }
//    7.将一个字符进行反转 abcdefg--->gfedcba
    public static void reversal(String str){
        char[] charArr = str.toCharArray();
        str = "";
        for(int i = 0; i < charArr.length / 2; i++){
            char tempChar = charArr[i];
            charArr[i] = charArr[charArr.length - 1 - i];
            charArr[charArr.length - 1 - i] = tempChar;
        }
        for(char c:charArr){
            str += c;
        }
        System.out.println(str);
    }
//    8获取两个字符串中最大相同子串"dsjakdjalk3218983djaskldjlsak""dsajhkldjasklas2313adsjlsa"-->"jaskl"
    public static void getSubset(String maxStr, String minStr){
        boolean flag = true;
        if(minStr.length() > maxStr.length()){
            String temp = minStr;
            minStr = maxStr;
            maxStr = temp;
        }
        for(int i = minStr.length(); i > 0 && flag; i--){
            for(int j = 0; j + i <= minStr.length() && flag; j++){
                String temp = minStr.substring(j,j+i);
                if(maxStr.contains(temp)){
                    System.out.println(minStr+"和"+maxStr+"的最大相同子串是:"+temp);
                    flag = false;
                }
            }
        }
    }
}
